package com.hyfrogx.modules.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hyfrogx.modules.information.entity.InfoClassify;
import com.hyfrogx.modules.information.dao.InfoClassifyDao;
import com.hyfrogx.modules.information.service.InformationClassifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author liubin
 * @date 2019/10/31 16:41
 */
@Service("InformationClassifyService")
@Slf4j
public class InformationClassifyServiceImpl extends ServiceImpl<InfoClassifyDao, InfoClassify> implements InformationClassifyService {

  @Override
  public List<InfoClassify> getAllClassifyForApi() {
    return this.baseMapper.selectList(new QueryWrapper<InfoClassify>().eq("classify_state",1));
  }

  @Override
  public Integer addInfoClassify(InfoClassify infoClassify) {
    Integer sort = this.baseMapper.findMaxSort();
    infoClassify.setSort(sort + 1);
    infoClassify.setCreateTime(new Date());
    infoClassify.setUpdateTime(new Date());
    infoClassify.setClassifyState(0);
    return this.baseMapper.insert(infoClassify);
  }

  @Override
  public void updateSort(List<InfoClassify> list) {
    this.baseMapper.updateSort(list);
  }
}
